-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
task: Drop the join waker of a task eagerly when the JoinHandle gets dropped or the task completes #6986
Conversation
f80d191
to
217b26d
Compare
dropped or the task completes Currently, the waker registered with a JoinHandle is not dropped until the task allocation is dropped. This behaviour may cause the memory allocated by a task to not be freed when in the case of two tasks awaiting each others JoinHandle. This commit changes the behaviour by actively dropping the waker when the JoinHandle gets dropped (or the task completes in some cases).
217b26d
to
163d841
Compare
eca9c26
to
c96a70d
Compare
c96a70d
to
d457bbb
Compare
* `State::transition_do_join_handle_drop` now returns a struct with to booleans to indicate what the JoinHandle should drop * Use `fetch_and` when unsetting JOIN_WAKER after COMPLETE
* Added missing ';' after unsafe blocks * Improved documentation in `State::transition_to_join_handle_dropped` on the scenarios in which `JOIN_WAKER` gets unset
46f40da
to
9f840cf
Compare
ref cycle test into a non-loom test (leaks will be detected by miri)
9f840cf
to
4733c9f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks. Only one comment below.
tokio/src/runtime/tests/task.rs
Outdated
#[test] | ||
fn drop_tasks_with_reference_cycle() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not use any Tokio internals, so it does not need to be inside src/
. It should be in tokio/tests/
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll move it for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh thanks I wasnt aware of this but will keep it in mind for the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. Thanks a lot for the PR!
Motivation
Currently, the waker registered with a JoinHandle is not dropped until the task allocation is dropped. This behaviour may cause the memory allocated by a task to not be freed when in the case of two tasks awaiting each others JoinHandle.
See #6505 for more details.
Solution
To prevent this we need to actively drop the waker when the
JoinHandle
gets dropped (or the task completes in some cases).Closes #6505.